package com.example.administrator.view;

import java.io.IOException;
import java.util.Map;
import java.util.concurrent.ConcurrentSkipListMap;
import okhttp3.Call;
import okhttp3.Response;
import android.os.Bundle;
import android.app.Activity;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.example.administrator.module.UrlDefine;
import com.example.administrator.testapk.R;
import com.example.administrator.utils.NetUtils;

public class AtyChangePwd extends Activity {
    private EditText et_oldpwd,et_newpwd,et_newpwd_repeat;
    private Button btn_sure;
    private TitleBar change_pwd_title;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.aty_change_pwd);
        initView();
    }
    private void initView() {
        change_pwd_title = (TitleBar)findViewById(R.id.change_pwd_title);
        change_pwd_title.setLeftImageResource(R.mipmap.back);
        change_pwd_title.setTitle("更改查询密码");
        change_pwd_title.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                finish();
            }
        });

        et_oldpwd = (EditText)findViewById(R.id.et_oldpwd);
        et_newpwd = (EditText)findViewById(R.id.et_newpwd);
        et_newpwd_repeat = (EditText)findViewById(R.id.et_newpwd_repeat);
        btn_sure = (Button)findViewById(R.id.btn_sure);
        btn_sure.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                sendAsynPostHttp();
            }
        });
    }
    private void sendAsynPostHttp() {
        String oldpwd = et_oldpwd.getText().toString();
        String newpwd = et_newpwd.getText().toString();
        String newpwdrepeat = et_newpwd_repeat.getText().toString();

        //两次密码不匹配的判断未添加
        if(TextUtils.isEmpty(oldpwd) || TextUtils.isEmpty(newpwd) || TextUtils.isEmpty(newpwdrepeat)){
            Toast.makeText(AtyChangePwd.this, "选项不应留空", Toast.LENGTH_SHORT).show();
        }else{
            //构造请求参数
            Map<String, String> reqBody = new ConcurrentSkipListMap<>();
            reqBody.put("oldPassword", oldpwd);
            reqBody.put("nPassword", newpwd);
            NetUtils.getInstance().postDataAsynToNet(UrlDefine.ACTION_URL_SETSEARCHPWD, reqBody, new NetUtils.MyNetCall() {

                @Override
                public void success(Call call, Response response) throws IOException {
                    // TODO Auto-generated method stub
                    final String setpwdData = response.body().string();
                    Log.e("setpwdData",setpwdData);
                }

                @Override
                public void failed(Call call, IOException e) {
                    // TODO Auto-generated method stub
                    e.printStackTrace();
                }
            });
        }
    }
}

